
/**
 * <p>
 * </p>
 *
 * @author zhuolin
 * @since 2020/5/27
 */
public class SuspendAndResumeDemo {

    public static Object o = new Object();

    public static class ChangeObjectThread extends Thread {
        public ChangeObjectThread(String name) {
            super.setName(name);
        }

        @Override
        public void run() {
            synchronized (o) {
                System.out.println(getName() + " start");
                Thread.currentThread().suspend();
                System.out.println(getName() + " end");
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new ChangeObjectThread("t1");
        Thread t2 = new ChangeObjectThread("t2");
        t1.start();
        Thread.sleep(100);
        t2.start();
        t1.resume();
        t2.resume();
        t1.join();
        t2.join();

    }
}
